<template>
	<div class="port-page">
		<div class="but1">
			<el-tabs v-model="activeName" type="card" @tab-click='tabchk'>
				<el-tab-pane label="全校" name="quanxiao"></el-tab-pane>
				<el-tab-pane label="老师" name="laoshi"></el-tab-pane>
				<el-tab-pane label="升级班级" name="banji"></el-tab-pane>
			</el-tabs>
		</div>
		<div style="width: 100%;float: left;">
			<div class="but">
				<router-link to="/home">
					<el-button type="warning" size="small" class="add btn" style='margin-right: 10px;' icon="el-icon-menu">首页</el-button>
				</router-link>
			</div>
			<div class="search" v-if="lstjlist">
				<div style="width: 300px;display: inline-block">
					<el-select v-model="vlsid" multiple placeholder="可选择多个老师检索" @change="search" style="width: 90%;">
						<el-option v-for="i in comboxlist" :label="i.mc" :value="i.id"></el-option>
					</el-select>
				</div>
				<div class="search-item">
					<div class="search-item">
						<el-date-picker v-model="vbtime" type="date" :editable="false" class="code-search" placeholder="开始日期" @keyup.enter.native="search" icon="search"></el-date-picker>
					</div>
					<span>-</span>
					<div class="search-item">
						<el-date-picker v-model="vetime" type="date" :editable="false" class="code-search" placeholder="结束日期" @keyup.enter.native="search" icon="search"></el-date-picker>
					</div>
				</div>
				<el-button type="primary" size="small" style="border-radius:13px;" class="add btn" :loading="searchLoading" @click="search" icon="el-icon-search"></el-button>
			</div>
		</div>
		<!-- 全校数据表格展示区域 -->
		<div v-if="qxtjlist" style="float: left;width: 100%;">
			<div id="main1" style="width: 100%;height: 400px;margin: 0 auto;"></div>
		</div>

		<!-- 老师数据表格展示区域 -->
		<div v-if="lstjlist">
			<el-table :data="lsList" border align="center" class="admin-table" @select="checkSelect" @select-all="checkall">
				<div slot='empty'>
					<img src="../../../assets/img/empty.png" style="width:40px;vertical-align: middle;">
					<span style="vertical-align: middle;">暂时还没有内容哦!</span>
				</div>
				<el-table-column :prop="v.prop" :label="v.label" v-for="(v,index) in portTitleList" align="center" show-overflow-tooltip v-if="v.hide != 0" :formatter="v.formatter" :align="v.align || 'center'" :fixed="v.fixed" :class-name="v.columnStyle" :width="v.width" :min-width="v.minWidth" :header-align="v.headerAlign || 'center'">
					<template scope="scope">
						<div slot="reference" :style="tableCellControl(scope)">
							{{ scope.row[scope.column.property] }}
						</div>
					</template>
				</el-table-column>
			</el-table>
		</div>
		<!-- 班级数据表格展示区域 -->

		<div v-if="bjtjlist">
			<el-table :data="bjList" border stripe size="small" align="center" class="admin-table" @select="checkSelect" @select-all="checkall">
				<!--<el-table-column type="selection" width="55"></el-table-column>-->
				<div slot='empty'>
					<img src="../../../assets/img/empty.png" style="width:40px;vertical-align: middle;">
					<span style="vertical-align: middle;">暂时还没有内容哦!</span>
				</div>
				<el-table-column :prop="v.prop" :label="v.label" v-for="(v,index) in portTitleList2" align="center" show-overflow-tooltip v-if="v.hide != 0" :formatter="v.formatter" :align="v.align || 'center'" :fixed="v.fixed" :class-name="v.columnStyle" :width="v.width" :min-width="v.minWidth" :header-align="v.headerAlign || 'center'">
					<template scope="scope">
						<div slot="reference" :style="tableCellControl(scope)">
							{{ scope.row[scope.column.property] }}
						</div>
					</template>
				</el-table-column>

			</el-table>
		</div>
		<LoadingComponent v-show="isLoading"></LoadingComponent>
		<router-view class="port-view"></router-view>
	</div>
</template>
<script>
	import { mapState } from 'vuex'
	import echarts from 'echarts'
	import LoadingComponent from 'components/loading'
	import qs from 'qs'
	export default {
		components: {
			LoadingComponent
		},
		data() {
			return {

				/*模糊搜索条件*/
				vlsid: [],
				vbtime: '',
				vetime: '',
				qxtjlist: true,
				lstjlist: false,
				bjtjlist: false,
				lsList: [], //表格数据
				bjList: [], //表格数据
				activeName: 'quanxiao',

				multipleDelNum: '', //获取批量选择的数据
				comboxlist: [], //下拉框 动态的
				vcomautovalue: '', //下拉框name 动态的
				vcomgdvalue: '', //下拉框name 固定的

				/*动画加载*/
				isLoading: true, //动画加载
				searchLoading: false, //搜索按钮触发按钮动画
				/*分页属性设置*/
				layout: 'total, sizes, prev, pager, next, jumper', //组件布局
				pageindex: this.$store.state.pageindex, //当前分页页码
				pagesizes: this.$store.state.pagesizes, //显示个数的选择器选项
				pagesize: this.$store.state.pagesize, //每页显示条目数
				total: 0, //总条数

				/*组件区域*/

				/*
				    prop :  接口参数名
				    label : 接口中文名
				    hide : 是否隐藏这一列
				    align : 这一列对齐顺序 ： left,right,center
				    headerAlign : 这一列表头对齐方式 ： left,right,center
				*/
				portTitleList: [

					{
						prop: 'zwm',
						label: '老师名称',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},

					{
						prop: 'bjs',
						label: '班级数',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'zrs',
						label: '班级人数',
						hide: 0,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'lsxs',
						label: '流失人数',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'lsv',
						label: '流失率',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'zrs',
						label: '现有人数',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'yyrs',
						label: '原有人数',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
				],
				portTitleList2: [{
						prop: 'ybjmc',
						label: '原班级名称',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'xybjmc',
						label: '现班级名称',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},

					{
						prop: 'lsmc',
						label: '原班级老师名称',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'lsmc1',
						label: '现班级老师名称',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'sjqrs',
						label: '原有班级人数',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'xybjrs',
						label: '现有班级人数',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'lsrs',
						label: '原班级流失人数',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'lsv',
						label: '流失率',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'xbl',
						label: '续班率',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
				]
			}
		},
		created() {
			//加载页面时调用
			this.$store.dispatch('changeTitle', '流失统计'); //修改title
			this.$store.dispatch('changeRouterIndex', '/statistics/xslstj'); //修改路由
			this.getcomboxlist();
			this.search('xxls'); //分页获取默认数据
			this.isLoading = true; //动画开始
		},
		mounted() {
			//加载完成之后event
			this.isLoading = false; //动画结束
		},
		methods: {
			getcomboxlist() {
				var logininfo = JSON.parse(localStorage.logininfo);
				this.searchLoading = true;
				var params2 = qs.stringify({
					yhid: logininfo.id,
					xxid: logininfo.xxid
				})
				//执行
				this.axios.post(this.$store.state.api + 'ls/getlslist', params2)
					.then(res => {
						console.log(res)
						let data = res.data.data;
						let list = data.list;
						this.comboxlist = list;
					}).catch(res => {
						console.log(res)
						this.searchLoading = false;
					})
			},
			tabchk(tab) {
				if(tab.name == 'quanxiao') {
					this.qxtjlist = true
					this.bjtjlist = false
					this.lstjlist = false
					this.search('xxls')
				} else if(tab.name == 'laoshi') {
					this.lstjlist = true
					this.bjtjlist = false
					this.qxtjlist = false
					this.search('bjls')
				} else if(tab.name == 'banji') {
					this.bjtjlist = true
					this.lstjlist = false
					this.qxtjlist = false
					this.search('sjls')
				}

			},
			//统计图
			drawPie2(id, lststr) {
				this.charts = echarts.init(document.getElementById(id))
				this.charts.setOption({
					title: {
						text: '全校统计',
						left: 'center'
					},
					tooltip: {
						trigger: 'item',
						formatter: "{b} : {c} ({d}%)"
					},
					legend: {
						// orient: 'vertical',
						// top: 'middle',
						bottom: 10,
						left: 'center',
						data: ['西凉', '益州', '兖州', '荆州', '幽州']
					},
					series: [{
						type: 'pie',
						radius: '65%',
						center: ['50%', '50%'],
						selectedMode: 'single',
						data: [{
								value: this.xscns,
								name: '本校当前总人数',
							},
							{
								value: this.lscns,
								name: '本校流失人数'
							},
						],
						itemStyle: {
							emphasis: {
								shadowBlur: 10,
								shadowOffsetX: 0,
								shadowColor: 'rgba(0, 0, 0, 0.5)'
							}
						}
					}]
				})
			},

			search(id) {
				var time1 = this.$.getLocalTimeNo0(Date.parse(this.vbtime));
				var time2 = this.$.getLocalTimeNo0(Date.parse(this.vetime));
				var logininfo = JSON.parse(localStorage.logininfo);
				var params3 = qs.stringify({
					day: 1,
					code: id,
					lsid: this.vlsid + '',
					bjtime: time1,
					edtime: time2,
					yhid: logininfo.id,
					xxid: logininfo.xxid,
				});
				this.searchLoading = true;
				this.axios.post(this.$store.state.api + 'ls/getlstj', params3)
					.then(res => {
					    this.$message.success(res.data.msg);
					    console.log(res, 999988887777)
						if(res.data.code == 1) {
							 var list = res.data.data.list
						  if(id == 'xxls'){
						  	this.lscns = list[0].lscns
						    this.xscns = list[0].xscns
						    this.$nextTick(function() {
								this.drawPie2('main1')
							});
						  }
						  if(id == 'bjls'){
						     this.lsList= list
						  }
						  if(id == 'sjls'){
						     this.bjList = list
						  }
						     this.searchLoading = false;
						} else {
							this.$message.warning(res.data.msg);
							this.$store.state.loading = false;
						}
					}).catch(res => {
						this.$message.error(res.data.msg);
						this.searchLoading = false;
					})
			},
			tableCellControl(scope) {
				//表格单元格控制CSS样式
				/*if (scope.row.id == 112 && scope.column.property == "iname") {
				    return {
				        color:"red",
				    }
				}else{
				    return {
				        color:"green",
				    }
				}*/
			},
			handleSizeChange(val) { //每页显示条数触发事件
				this.pagesize = val;
				this.pageindex = 1;
				this.search();
			},
			handleCurrentChange(val) { //分页触发事件
				this.search();
			},
			checkSelect(selection, row) { //点击单选select触发事件
				console.log(selection, row)
				let strID = [];
				selection.forEach(function(v, i) {
					strID.push(v.id)
				})
				this.multipleDelNum = strID.join(",");
			},
			checkall(selection) { //点击全选select触发事件
				let strID = [];
				selection.forEach(function(v, i) {
					strID.push(v.id)
				})
				this.multipleDelNum = strID.join(",");
			},
			/* 组件的弹框  */
			componentsShow(type, data) { //显示组件
				console.log(type, data)
				for(let i in this.portComponents) {
					if(type == this.portComponents[i].type) {
						this.portComponents[i].toggle = true;
						this.portComponents[i].params = data;
						if(this.portComponents[i].data.type == 'single') {
							this.portComponents[i].data.index = data.row.id
						} else if(this.portComponents[i].data.type == 'multiple') {
							this.portComponents[i].data.index = this.multipleDelNum;
						} else {
							return;
						}
						return;
					}
				}
			},
			componentsHide(setting) { //关闭组件
				console.log(setting)
				for(let i in this.portComponents) {
					if(setting.type == this.portComponents[i].type) {
						this.portComponents[i].toggle = false;
						if(!setting.cancel) {
							this.search();
						}
						return;
					}
				}
			}
		},
		computed: {
			...mapState([
				'api' //域名
			]),
			multipleDeleteDisabled() {
				console.log(this.multipleDelNum)
				if(this.multipleDelNum) {
					return false;
				} else {
					return true
				}
			}
		}
	}
</script>

<style lang="less" scoped>
	.port-page {
		font-size: 12px;
		.btn {
			height: 30px;
			padding: 0 10px;
		}
		.code-search {
			max-width: 130px;
			min-width: 100px;
			text-align: center;
			height: 50px;
			/*line-height: 50px;*/
			font-size: 12px;
		}
		.class-page {
			text-align: left;
			margin-top: 10px;
		}
		.search-item {
			display: inline-block;
		}
		.but1 {
			width: 100%;
			float: left;
			margin-top: 10px;
		}
		.but {
			width: 30%;
			height: 50px;
			line-height: 50px;
			float: left;
		}
		.search {
			width: 70%;
			height: 50px;
			float: right;
			text-align: right;
		}
		.search {
			width: 70%;
			height: 50px;
			line-height: 50px;
			float: right;
			text-align: right;
		}
	}
</style>